//
//  HZOrderByerAddressModel.m
//  app
//
//  Created by 刘华舟 on 15/5/11.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZOrderByerAddressModel.h"
#import "NSDictionary+SafetyGet.h"

@implementation HZOrderByerAddressModel

+ (instancetype)modelWithDictionary:(NSDictionary *)dict{
    return [[HZOrderByerAddressModel alloc] initModelWithDictionary:dict];
}

- (instancetype)initModelWithDictionary:(NSDictionary *)dict{
    if (self = [super init]) {
        _addressID = [dict stringForKey:APIKEY_mall_id nilValue:@"0"];
        _nation = [dict stringForKey:APIKEY_mall_nation nilValue:@""];
        _province = [dict stringForKey:APIKEY_mall_province nilValue:@""];
        _city = [dict stringForKey:APIKEY_mall_city nilValue:@""];
        _district = [dict stringForKey:APIKEY_mall_district nilValue:@""];
        _address = [dict stringForKey:APIKEY_mall_address nilValue:@""];
        _postcode = [dict stringForKey:APIKEY_mall_postcode nilValue:@""];
        _phone = [dict stringForKey:APIKEY_mall_phone nilValue:@""];
        _receiver = [dict stringForKey:APIKEY_mall_receiver nilValue:@""];
        NSString *maskName = _receiver;
        if (maskName.length >= 2) {
            maskName = [_receiver stringByReplacingCharactersInRange:NSMakeRange(1, _receiver.length-1) withString:@"**"];
        }
        _receiver = maskName;
        _fullAddress = [dict stringForKey:APIKEY_mall_fullAddress nilValue:@""];
        
        _defaultAddress = [dict boolForKey:APIKEY_mall_selected];
    }
    return self;
}

- (void)setGroupName:(NSString *)groupName{
    _groupName = groupName;
    _buildingName = nil;
    _roomName = nil;
    _fullAddress = [NSString stringWithFormat:@"%@%@", _cmName, _groupName];
}

- (void)setGroupID:(NSString *)groupID{
    _groupID = groupID;
    _buildingID = nil;
    _roomID = nil;
    
}

- (void)setBuildingName:(NSString *)buildingName{
    _buildingName = buildingName;
    _roomID = nil;
    
    _fullAddress = [NSString stringWithFormat:@"%@%@", _groupName, _buildingName];
}

- (void)setBuildingID:(NSString *)buildingID{
    _buildingID = buildingID;
    _roomID = nil;
}

- (void)setRoomName:(NSString *)roomName{
    _roomName = roomName;
    
    _fullAddress = [NSString stringWithFormat:@"%@%@%@", _groupName, _buildingName, _roomName];
}
@end
